package com.panda.admin.result;

import java.io.Serializable;

/**
 * author: tcy
 * createDate: 2023/5/19
 * description: 系统执行状态返回
 */
public enum ResultCode implements Serializable {

    SUCCESS("200", "操作成功"),
    FAIL("500","操作失败"),
    TOKEN_INVALID_OR_EXPIRED("401", "令牌无效或过期"),
    TOKEN_UNAUTHORIZED("402", "令牌未授权"),
    TOKEN_NOT_CERTIFIED("403", "令牌未认证"),
    TOKEN_ACCESS_FORBIDDEN("404", "令牌拉黑无效"),
    USER_ERROR("A0001", "用户端错误"),
    USER_LOGIN_ERROR("A0200", "用户登录异常"),
    USER_NOT_EXIST("A0201", "用户不存在"),
    USER_ACCOUNT_LOCKED("A0202", "账户被冻结"),
    USER_ACCOUNT_INVALID("A0203", "账户已作废"),
    USER_ROLE_INVALID("A0204", "当前用户没有绑定角色"),
    USERNAME_PASSWORD_ERROR("A0210", "密码错误"),
    PASSWORD_ENTER_EXCEED_LIMIT("A0211", "用户输入密码次数超限"),
    CLIENT_AUTHENTICATION_FAILED("A0212", "客户端认证失败"),
    AUTHORIZED_ERROR("A0300", "访问权限异常"),
    ACCESS_UNAUTHORIZED("A0301", "访问未授权"),
    PARAM_ERROR("A0400", "用户请求参数错误"),
    RESOURCE_NOT_FOUND("A0401", "请求资源不存在"),
    PARAM_IS_NULL("A0410", "请求必填参数为空"),
    USER_UPLOAD_FILE_ERROR("A0700", "用户上传文件异常"),
    USER_UPLOAD_FILE_TYPE_NOT_MATCH("A0701", "上传文件类型不匹配"),
    USER_UPLOAD_FILE_SIZE_EXCEEDS("A0702", "上传文件太大"),
    SYSTEM_EXECUTION_ERROR("B0001", "系统执行出错"),
    SYSTEM_EXECUTION_TIMEOUT("B0002", "系统执行超时"),
    FLOW_LIMITING("B0003", "系统限流"),
    DEGRADATION("B0004", "系统功能降级"),
    SYSTEM_RESOURCE_ERROR("B0005", "系统资源异常"),
    CALL_THIRD_PARTY_SERVICE_ERROR("C0001", "调用第三方服务出错");

    private String code;
    private String msg;

    public String getCode() {
        return this.code;
    }

    public String getMsg() {
        return this.msg;
    }

    public String toString() {
        return "{\"code\":\"" + this.code + '"' + ", \"msg\":\"" + this.msg + '"' + '}';
    }

    public static ResultCode getValue(String code) {
        ResultCode[] codes = values();
        for (ResultCode resultCode : codes) {
            if (resultCode.getCode().equals(code)){
                return resultCode;
            }
        }
        return SYSTEM_EXECUTION_ERROR;
    }

    private ResultCode(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResultCode() {
    }

}
